package com.travel.bhelp.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.travel.bhelp.common.model.Result;
import com.travel.bhelp.user.model.JobPost;
import com.travel.bhelp.user.repository.JobPostMapper;
import com.travel.bhelp.user.service.JobPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class JobPostServiceImpl implements JobPostService {

    @Autowired
    private JobPostMapper jobPostMapper;

    @Override
    public Result createJobPost(JobPost jobPost) {
        jobPost.setStatus(0); // 默认未开始状态
        jobPostMapper.insert(jobPost);
        return Result.success("用工信息发布成功");
    }

    @Override
    public Result updateJobPost(JobPost jobPost) {
        jobPostMapper.updateById(jobPost);
        return Result.success("用工信息更新成功");
    }

    @Override
    public Result deleteJobPost(Long id) {
        jobPostMapper.deleteById(id);
        return Result.success("用工信息删除成功");
    }

    @Override
    public List<JobPost> getJobPostsByUser(Long userId) {
        QueryWrapper<JobPost> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        return jobPostMapper.selectList(wrapper);
    }

    @Override
    public List<JobPost> getAllJobPosts() {
        return jobPostMapper.selectList(null);
    }
}
